﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DreamBuilder.DictionaryAccess;
using DreamBuilder.UI.UserControls.DataAccess.Services;


namespace DreamBuilder.UI.UserControls.DataAccess.Components
{
    public class MsSqlUCSearchDAL : UCSearchDAL
    {
        public override void HandleRightExpress(FieldDicInfo pFieldDicInfo, ref string sRightExpress)
        {
            switch (pFieldDicInfo.FieldType)
            {
                case FIELDTYPE.TYPE_Float:
                case FIELDTYPE.TYPE_Decimal:
                    sRightExpress = " cast('" + sRightExpress + "' AS decimal(19,6)) ";
                    break;
                case FIELDTYPE.TYPE_Integer:
                    sRightExpress = " cast('" + sRightExpress + "' AS int) ";
                    break;
                case FIELDTYPE.TYPE_Bool:
                    sRightExpress = " cast((case '" + sRightExpress + "' when 'True' then 1 else 0 end) AS bit) ";
                    break;
                case FIELDTYPE.TYPE_String:
                case FIELDTYPE.TYPE_Reference:
                    sRightExpress = "'" + sRightExpress + "'";
                    break;
                case FIELDTYPE.TYPE_Date:
                    sRightExpress = "'" + sRightExpress + "'";
                    break;
                default:
                    sRightExpress = "'" + sRightExpress + "'";
                    break;
            }
        }
        public override string GenerateNullValueExpress(FieldDicInfo pFieldDicInfo)
        {
            return pFieldDicInfo.TableCode + "." + pFieldDicInfo.FieldCode + " is null or len(" + pFieldDicInfo.TableCode + "." + pFieldDicInfo.FieldCode + ") = 0 ";
        }

    }
}
